package com.example.service;

import com.example.entity.MonitoringData;
import com.example.mapper.MonitoringDataMapper;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;

@Service
public class MonitoringDataService {
    private final MonitoringDataMapper monitoringDataMapper;

    public MonitoringDataService(MonitoringDataMapper monitoringDataMapper) {
        this.monitoringDataMapper = monitoringDataMapper;
    }

    public List<MonitoringData> getAllData() {
        return monitoringDataMapper.selectAll();
    }

    public List<MonitoringData> getDataBySiteId(Integer siteId) {
        return monitoringDataMapper.selectBySiteId(siteId);
    }

    public List<MonitoringData> getDataByRecordedAt(LocalDate recordedAt) {
        return monitoringDataMapper.selectByRecordedAt(recordedAt);
    }

    public List<MonitoringData> getDataByFamilyId(Integer familyId) {
        return monitoringDataMapper.selectByFamilyId(familyId);
    }

    @Transactional
    public boolean deleteData(Long dataId) {
        return monitoringDataMapper.deleteById(dataId) > 0;
    }

    @Transactional
    public boolean addData(MonitoringData data) {
        return monitoringDataMapper.insert(data) > 0;
    }

    @Transactional
    public boolean updateData(MonitoringData data) {
        return monitoringDataMapper.update(data) > 0;
    }

    public MonitoringData getDataById(Long dataId) {
        return monitoringDataMapper.selectById(dataId);
    }
} 